package components.scanario
{
	import UIFree.ObjectEvent;
	import UIFree.command.uif_commandManager;
	import UIFree.components.uif_window;
	import UIFree.controls.uif_gbutton;
	import UIFree.controls.uif_popupMenu;
	import UIFree.uif_Timer;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import classes.c_events;
	import classes.c_locale;
	import classes.c_uiEvents;
	
	import components.c_component;
	import components.c_image;
	import components.player.c_playerWindow;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class c_assistantAreaV extends c_component {
		private var _assistantImage	: c_assistantImage;
		private var _menu			: uif_popupMenu;
		private var _player			: c_playerWindow;
		public function c_assistantAreaV(a_parent: uif_component, styleClass:Object='') {
			var rect: Rectangle = a_parent.getInner();
			super(a_parent, rect.x, rect.y, rect.width, rect.height, styleClass);
		}
		
		override protected function listenEvents():void {
			super.listenEvents();
			addEvent(c_uiEvents.ASSISTENT, doAssistent, workspace)
		}
		
		private function doAssistent(e: Event): void {
			_assistantImage.slideShow();
		}
		
		override protected function createComponents(): void {
			super.createComponents();
			var inner: Rectangle = app.getInner();
			_assistantImage		 = new c_assistantImage(this, inner.x + inner.width - 200, inner.y + inner.height - 200, c_images.ASSISTANT_01, style.assistant);
			_assistantImage.setVisibility(false);
			_assistantImage.addEvent(Event.CLOSE, doCloseImage);
			
			_menu = new uif_popupMenu(cl.topLayer, {
				orientation	: uif_popupMenu.LEFTPOSITION,
				itemClass	: uif_gbutton,
				showEvent	: MouseEvent.ROLL_OVER				
			}, 100, 100, 'popupmenu');
			
			_menu.activeControl = _assistantImage;
			_menu.listMenu 		= listMenu();
			_menu.addEvent(Event.SELECT, doMenuSelect);
//			_assistantImage.text = 'Привет всем!';
		}
		
		private function doMenuSelect(e: ObjectEvent): void {
			play(e.object.caption, e.object.video);
		}
		
		protected function listMenu(): Array {
			return [
				{
					caption	: 'Как создать многослойное 3D изображение',
					video	: 'https://www.youtube.com/v/99YpIz_0kjI'  
				},{
					caption	: 'Как вставить фото в рамку',
					video	: 'https://www.youtube.com/v/MTU6ZwluJ7k'  
				},{
					caption	: 'Как фотографии вставить в рамку с несколькими вырезами',
					video	: 'https://www.youtube.com/v/1jnbsMA_UNc'  
				},{
					caption	: 'Как перевоплотиться',
					video	: 'https://www.youtube.com/v/riU0mrZkQH8'  
				}
			]
		}
		
		private function play(a_title: String, url: String): void {
			if (!_player) _player = new c_playerWindow(cl.topLayer, a_title, false, uif_window.CLOSEHIDE);
			_player.load(url, function(): void {
				_player.show();
			});
		}
		
		private function removePlayer(): void {
			_player.dispose();
			_player = null;
		}
		
		private function doCloseImage(e: Event): void {
			if (_player) removePlayer();
		}
		
		override public function dispose():void {
			_menu.dispose();
			removePlayer();
			super.dispose();
		}
	}
}